<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>08_猜数字练习</title>
</head>
<body>
<h3>已生成一个1~100之间的随机数:</h3>
<input type="number" placeholder="请输入你猜的数字" id="num">
<button onclick="f()">点我验证</button>
<h3>小提示:<span></span></h3>
<script>
    let n = parseInt(Math.random() * 100) + 1;

    function f() {
        let num = document.getElementById('num').value;
        num = parseFloat(num);
        let spanE = document.querySelector('span');
        if (num > n) {
            spanE.innerHTML = '猜大了'
        } else if (n > num) {
            spanE.innerHTML = '猜小了'
        } else if (num==n){
            spanE.innerHTML = '猜对了'
        }
    }


</script>


</body>
</html>